import { defineStore } from 'pinia';
import { appStore } from './interface';
import en from 'element-plus/es/locale/lang/en';
import zhCn from 'element-plus/es/locale/lang/zh-cn';

export const useAppStore = defineStore('appInfo', {
	state: (): appStore => ({
		app: {
			site_name: '管理系统',
			site_logo: '',
		},
		allUser: 0,
		todayUser: 0,
		toDayLogin: 0,
		weekRegUsers: [],
		weekLoginUsers: [],
		threeDayUser: 0,
		sevenDayUser: 0,
		applicationUsers: {},
		allResource: 0,
		todayResource: 0,
		locale: zhCn,
	}),
	getters: {
		appName: (state) => {
			return state.app.site_name;
		},
	},
	actions: {
		setAppInfo({
			config,
			allUser,
			todayUser,
			toDayLogin,
			weekRegUsers,
			weekLoginUsers,
			threeDayUser,
			sevenDayUser,
			applicationUsers,
			allResource,
			todayResource,
		}: any) {
			this.app = config;
			this.allUser = allUser;
			this.todayUser = todayUser;
			this.toDayLogin = toDayLogin;
			this.weekRegUsers = weekRegUsers;
			this.weekLoginUsers = weekLoginUsers;
			this.threeDayUser = threeDayUser;
			this.sevenDayUser = sevenDayUser;
			this.applicationUsers = applicationUsers;
			this.allResource = allResource;
			this.todayResource = todayResource;
		},
		setLang(lang: string) {
			if (lang === 'zh-CN') {
				this.locale = zhCn;
			} else {
				this.locale = en;
			}
		},
	},
});
